package org.mech.sefer.client.ui.task.executor.impl;

import org.apache.commons.lang.Validate;
import org.apache.pivot.util.concurrent.Task;
import org.mech.sefer.client.ui.task.TaskConfig;
import org.mech.sefer.client.ui.task.callback.TaskCallback;
import org.mech.sefer.client.ui.task.executor.TaskExecutor;
import org.mech.sefer.client.ui.task.listener.DefaultTaskListener;
import org.springframework.stereotype.Component;

@Component("taskExecutor")
public class TaskExecutorImpl implements TaskExecutor {

	@Override
	public <T> void execute(Task<T> task, TaskCallback<T> callback) {
		Validate.notNull(task);
		Validate.notNull(callback);

		task.execute(new DefaultTaskListener<T>(callback));
	}

	@Override
	public <T> void execute(TaskConfig<T> taskConfig) {
		execute(taskConfig.getTask(), taskConfig.getCallback());
	}

}
